/****************************************************************
 * Copyright(C),2012-2015, 浙江维尔科技股份有限公司
 * File name:
 * Author: kf		Version: 1.0.0.1		Date: 2012-03-08
 * Description: 指纹设备接口(JNI)
 * History:
 * 1. Date:
 *    Author:
 *    Modification:  
****************************************************************/

package com.wellcom.finger;

import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbDeviceConnection;
import android.hardware.usb.UsbManager;
import android.os.Handler;
import android.util.Log;

import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Iterator;

public class FpDriverV22 {


	public static int isLoadOK;


	static
	{
		//System.out.println(System.getenv("classpath"));

		//BasicConfigurator.configure();
		//PropertyConfigurator.configure("log4j.properties");
		//logger.BasicConfigurator()
		// System.out.println("user.dir="+System.getProperty("user.dir"));
		// System.out.println("java.library.path="+System.getProperty("java.library.path"));
		String strLibPath="";
		try{

			//IFpDevDriver.logger.debug("====debug");

			isLoadOK = 0;
			// 方式一：从Java环境路径中加载库文件(使用System.loadLibrary从相对路径加载)
			//System.load("/data/com.example.fingerdemo/lib/libfpdriver.so");
			//System.loadLibrary("devapi");
			System.loadLibrary("FpDriverV22");


			 /*
			 // 方法二：从项目中或其它路径中加载库文件(使用System.load从绝对路径加载)
			 if(isWindowsOS()){
				  strLibPath = fullProjectPath("YGQD_WELLCOM_FINGER.dll");
				  strLibPath = strLibPath.substring(1);
				  System.out.println("load library {" + strLibPath + "} OK:");

				  System.load(strLibPath);
			  }else{
				  strLibPath = fullProjectPath("YGQD_WELLCOM_FINGER.so");

				  System.out.println("load library {" + strLibPath + "} OK:");
				  System.load(strLibPath);

			  }
			  */
		}
		catch(Throwable  ex){
			isLoadOK = 1;
	        ex.printStackTrace();
		}
	}
	
	/**
	  * 本地方法声明
	  */
	// 设备库
    public static native String[] FPIGetDllVersion();
    public static native String   FPIGetErrorInfo (int nErrorCode);
    public static native int  FPIPowerOn();
    public static native int  FPIPowerOff();
    public static native int  FPIDeviceInitRS232(byte[] psComFile, int baudrate, int flags);
	public static native int  FPIDeviceInit(int fd, String devNode);
	public static native int  FPIDeviceClose();
	public static native int  FPIGetVersion(byte[] psDevVersion);
	public static native int  FPIGetDeviceID (byte[] psFactoryID);
	public static native int  FPIGetFeature (int nTimeOut, byte[] psFeatureBuf, int[] pnLength);
	public static native int  FPIGetTemplate (int nTimeOut, byte[] psTemplateBuf, int[] pnLength);
	public static native int  FPIGetImage(int nTimeout, byte[] psImageBuf, int[] pnLength, byte[] psBmpFile);
	public static native int  FPIGetImageEx(int nTimeout, byte[] psImageBuf, int[] pnLength, int[] iIsValid, int[] piQuality, byte[] psBmpFile);
	public static native int  FPICheckFinger();
	public static native int  FPICheckImage (byte[] psImage, int[] pnErrType, byte[] psErrMsg, byte[] psSuggest);
	public static native void FPICancel();
	
	public static native int  FPIGatherEnroll(int cGatherNO, int nTimeOut);
	public static native int  FPISynEnroll(int nGatherNum);
	public static native int  FPIGetFeatureAndImage(int nTimeOut, byte[] psFpData, int[] pnFpDataLen, byte[]  psImageBuf, int[] pnImasgeLen, byte[] psBmpFile);



	// 算法库 
	public static native int  FPICryptBase64(int nMode, byte[] psInput, int nInLen, byte[] psOutput, int[] pnOutlen);
	public static native int  FPIFpVerify(byte[] psRegBuf, byte[] psVerBuf, int nLevel);
	public static native int  FPIGetFeatureByImg(byte[] psImage,  byte[] psVerBuf, int[] pnLength);
	public static native int  FPIGetTemplateByImg(byte[] psImage1, byte[] psImage2, byte[] psImage3, byte[] psRegBuf, int[] pnLength);
	public static native int  FPIFpMatch(byte[] mb, byte[] tz, int level);
	public static native int  FPIEnrollX(byte[] psTZ1, byte[] psTZ2, byte[] psTZ3, byte[] psRegBuf, int[] pnLength);
	public static native int  FPISaveBMP(String file, byte[] imgBuf);
	

}
	